package com.example.friend.controller;


import com.example.core.controller.BaseController;
import com.example.core.domain.R;
import com.example.core.domain.TableDataInfo;
import com.example.core.enums.ResultCode;
import com.example.friend.domain.dto.QuestionSearchDTO;
import com.example.friend.domain.vo.QuestionESVO;
import com.example.friend.domain.vo.QuestionVO;
import com.example.friend.service.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/question")
@Tag(name = "题目API")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    @Operation(summary = "题目列表")
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(QuestionSearchDTO searchDTO) {
        return questionService.selectQuestionList(searchDTO);
    }

    @Operation(summary = "题目列表")
    @GetMapping("/semiLogin/hotList")
    public R<List<QuestionVO>> hotList() {
        return R.ok(questionService.selectHotQuestionList());
    }

    @Operation(summary = "题目列表")
    @GetMapping("/semiLogin/search")
    public TableDataInfo search(QuestionSearchDTO searchDTO) {
        return questionService.search(searchDTO);
    }

    @Operation(summary = "题目详情")
    @GetMapping("/detail")
    public R<QuestionESVO> detail(Long questionId) {
        QuestionESVO question = questionService.detail(questionId);
        return R.ok(question);
    }

    @Operation(summary = "上一题")
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long questionId) {
        Long preQuestionId = questionService.preQuestion(questionId);
        return R.ok(ResultCode.SUCCESS.getMsg(), String.valueOf(preQuestionId));
    }

    @Operation(summary = "下一题")
    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long questionId) {
        Long nextQuestionId = questionService.nextQuestion(questionId);
        return R.ok(ResultCode.SUCCESS.getMsg(), String.valueOf(nextQuestionId));
    }
}
